<?php
class ShowHooks_Listener {

	public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template) {
		$options = XenForo_Application::get('options');
		$visitor = XenForo_Visitor::getInstance();
		$userid = $visitor['user_id'];
		if($hookName != '' && $hookName == "message_user_info_text"){
			$span = ShowHooks_Listener::GetBetween("<span","span>",$contents);
			$oldText = "<span".$span."span>";//replace this with new style later
			//Get username
			$username = ShowHooks_Listener::GetBetween(">","<",$span);
			//Create new style
			$style = '<span class="style7">'.$username.'</span>';
			//Replace
			$pos = strpos($contents, $oldText);
			$contents = str_replace($oldText, $style, $contents);
		}
	}
	public static function getInnerSubstring($string,$delim){
		// "foo a foo" becomes: array(""," a ","")
		$string = explode($delim, $string, 3); // also, we only need 2 items at most
		// we check whether the 2nd is set and return it, otherwise we return an empty string
		return isset($string[1]) ? $string[1] : '';
	}
	public static function GetBetween($var1="",$var2="",$pool){
		$temp1 = strpos($pool,$var1)+strlen($var1);
		$result = substr($pool,$temp1,strlen($pool));
		$dd=strpos($result,$var2);
		if($dd == 0){
			$dd = strlen($result);
		}

		return substr($result,0,$dd);
	}
}
